package com.company.笔试.最长无重复子数组;

import java.util.LinkedList;
import java.util.Queue;

/**
 * @ClassName Solution
 * @Description TODO
 * @Author 11
 * @Date 2021/6/7 21:36
 * @Version 1.0
 */
public class Solution {

    public int maxLength (int[] arr) {
        // write code here
        Queue<Integer> queue = new LinkedList<>();
        int resMaxLength=0;
        for (int num:arr) {
            while (queue.contains(num)){
                //如果包含则出队列
                queue.poll();
            }
            queue.add(num);//num入队
            resMaxLength = Math.max(resMaxLength,queue.size());
        }
        
        return resMaxLength;
    }
}
